<?php
global $woodb;
$course_id = isset($_GET["course_id"]) ? $_GET["course_id"] : null;
$lecture_id = isset($_GET["lecture_id"]) ? $_GET["lecture_id"] : null;
// $course = $woodb -> getCourseByID($course_id);
// $lectures = $woodb->getLectures($course_id);

$materials = $woodb -> getMaterials($lecture_id);

?>
<div class="wrap" >
	<h2>Material</h2>
	<p></p>
	<table id="materials" cellspacing="0">
		<thead>
			<tr>
				<th>Name</th>
				<th>Type</th>
				<th>Actions</th>
			</tr>
		</thead>
		<tfoot>
			<tr>
				<th>Name</th>
				<th>Type</th>
				<th>Actions</th>
			</tr>
		</tfoot>
		<tbody>
			<?php foreach ($materials as $m) {
		echo "<tr>
			<td onclick='jQuery(this).downloadFile(\"".$m->guid."\")' class='edit_lecture'>$m->name</td>
			<td align='center'>".ucfirst($m->type)."</td>
			<td align='center'>
				<img onclick='jQuery(this).deleteMaterial($course_id, $lecture_id, $m->material_id);' title='Delete Material' class = 'remove_lecture' style='height:22px; width:22px' src='" . get_bloginfo('wpurl') . "/wp-content/plugins/woodle/css/images/delete.png'/>
			</td>
			</tr>";
		}
			?>
		</tbody>
	</table>
	<p style='padding-top:10px'></p>
	<form id="file-form" enctype="multipart/form-data" action="admin.php?page=woodle_admin&goto=woodle_edit_lecture&action=woodle_upload_file&course_id=<?=$course_id?>&lecture_id=<?=$lecture_id?>" method="POST">

		<p id="async-upload-wrap">
			<h3>Add Material</h3>
		<p></p>
		<select name="material_type">
			<option value="presentation" selected="selected">Presentation</option>
			<option value="solution">Solution</option>
			<option value="assignment">Assignment</option>
			<option value="article">Article</option>
			<option value="tutorial">Tutorial</option>
		</select>
		<input type="file" id="async-upload" name="async-upload">
		<input type="submit" value="Upload" name="html-upload">
		</p>
		<p>
			<input type="hidden" name="lecture_id" id="lecture_id" value="<?=$lecture_id?>" />
			<?php wp_nonce_field('client-file-upload')
			?>
			<input type="hidden" name="redirect_to" value="admin.php?page=woodle_admin&action=woodle_edit_lecture&lecture_id=<?=$lecture_id?>" />
		</p>
		<p>
			<input type="submit" value="Save all changes" name="save" style="display: none;">
		</p>

	</form>
	<div id="import_mat" style='display:none' title='Import existing material'></div>
	<p class="submit">
		<input onclick="jQuery(this).importMaterial(<?=$course_id.",".$lecture_id?>)" type="submit" class="button-primary" value="Import Material" />
	</p>
</div>